﻿(function () {
    function UploadPicDialog(editor) {

        return {
            title: '上传图片',
            minWidth: 550,
            minHeight: 380,
            buttons: [
                CKEDITOR.dialog.okButton,
                CKEDITOR.dialog.cancelButton],
                contents:
                [
                    {
                        id: 'frame',
                        label: '',
                        title: '',
                        elements: [{
                            type: "html",
                            html: '<iframe height="350" src="'+_global.url.upload+'" id="editor-upload-frame" style="border: none; padding: 0; width: 100%; height: 350px;"></iframe>',
                            commit: function (editor) {
                                 var images = $("#editor-upload-frame")[0].contentWindow.image.get();
                                 for(var i in images) {
                                     var html = '<img src="'+images[i].fileUrl+'">';
                                    editor.insertHtml(html);
                                 }
                                $("#editor-upload-frame")[0].contentWindow.location.reload() ;
                            }
                        }]
                    }
                ],
            onOk: function () {
                this.commitContent(editor);
                this.setupContent();
            },
            resizable: CKEDITOR.DIALOG_RESIZE_HEIGHT
        };
    }

    CKEDITOR.dialog.add('UploadPic', function (editor) {
        return UploadPicDialog(editor);
    });
})();